#include "SemanticNodeBlockWait.h"

/**
 *  @fn	SemanticNodeBlockWait::SemanticNodeBlockWait(const SyntaxTreeNode *waitNodeParent,
 *  	SemanticNode *parent)
 * 
 *  @brief	Constructor. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	waitNodeParent	If non-null, the wait node parent.
 *  @param	parent			If non-null, the parent.
 */
SemanticNodeBlockWait::SemanticNodeBlockWait(const SyntaxTreeNode *waitNodeParent, SemanticNode *parent) : SemanticNode(parent), LabeledNode(waitNodeParent->Nodes->GetData(0)) {
	const SyntaxTreeNode *theNode = waitNodeParent->Nodes->GetData(1)->Nodes->GetData(0);
	sensitivityList = (theNode->Nodes->GetData(1)->Nodes->GetCount() > 0);
	queue = (theNode->Nodes->GetData(2)->Nodes->GetCount() > 0);
	whileUntil = (theNode->Nodes->GetData(3)->Production == Gr_WhileUntil__until);
	thenStructure = (theNode->Nodes->GetData(7)->Nodes->GetCount() > 0);
	elseStructure = (theNode->Nodes->GetData(8)->Nodes->GetCount() > 0);
	timeout = (theNode->Nodes->GetData(9)->Nodes->GetCount() > 0);
	timeoutStructure = (timeout && (theNode->Nodes->GetData(9)->Production == Gr_Timeout__timeout_Expression_spLCBrac_ModelStructure_spRCBrac));
}
/**
 *  @fn	void SemanticNodeBlockWait::setCondition(SemanticNodeExpression *cond)
 * 
 *  @brief	Sets a condition. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	cond	If non-null, the cond.
 */
void SemanticNodeBlockWait::setCondition(SemanticNodeExpression *cond) {
	condition = cond;
}
/**
 *  @fn	void SemanticNodeBlockWait::setQueue(SemanticNodeExpression *q)
 * 
 *  @brief	Sets a queue. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	q	If non-null, the.
 */
void SemanticNodeBlockWait::setQueue(SemanticNodeExpression *q) {
	formingQueue = q;
}
/**
 *  @fn	void SemanticNodeBlockWait::setTimeout(SemanticNodeExpression *tout)
 * 
 *  @brief	Sets a timeout. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	tout	If non-null, the tout.
 */
void SemanticNodeBlockWait::setTimeout(SemanticNodeExpression *tout) {
	timeoutExpression = tout;
}
/**
 *  @fn	bool SemanticNodeBlockWait::isWaitWhile(void)
 * 
 *  @brief	Query if this object is wait while. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @return	true if wait while, false if not.
 */
bool SemanticNodeBlockWait::isWaitWhile(void) {
	return !whileUntil;
}
/**
 *  @fn	bool SemanticNodeBlockWait::isWaitUntil(void)
 * 
 *  @brief	Query if this object is wait until. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @return	true if wait until, false if not.
 */
bool SemanticNodeBlockWait::isWaitUntil(void) {
	return whileUntil;
}
/**
 *  @fn	bool SemanticNodeBlockWait::hasSensitivityList(void)
 * 
 *  @brief	Query if this object has sensitivity list. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @return	true if sensitivity list, false if not.
 */
bool SemanticNodeBlockWait::hasSensitivityList(void) {
	return sensitivityList;
}
/**
 *  @fn	bool SemanticNodeBlockWait::hasExplicitQueue(void)
 * 
 *  @brief	Query if this object has explicit queue. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @return	true if explicit queue, false if not.
 */
bool SemanticNodeBlockWait::hasExplicitQueue(void) {
	return queue;
}
/**
 *  @fn	bool SemanticNodeBlockWait::hasThenStructure(void)
 * 
 *  @brief	Query if this object has then structure. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @return	true if then structure, false if not.
 */
bool SemanticNodeBlockWait::hasThenStructure(void) {
	return thenStructure;
}
/**
 *  @fn	bool SemanticNodeBlockWait::hasElseStructure(void)
 * 
 *  @brief	Query if this object has else structure. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @return	true if else structure, false if not.
 */
bool SemanticNodeBlockWait::hasElseStructure(void) {
	return elseStructure;
}
/**
 *  @fn	bool SemanticNodeBlockWait::hasTimeout(void)
 * 
 *  @brief	Query if this object has timeout. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @return	true if timeout, false if not.
 */
bool SemanticNodeBlockWait::hasTimeout(void) {
	return timeout;
}
/**
 *  @fn	bool SemanticNodeBlockWait::hasTimeoutExpression(void)
 * 
 *  @brief	Query if this object has timeout expression. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @return	true if timeout expression, false if not.
 */
bool SemanticNodeBlockWait::hasTimeoutBlock(void) {
	return timeoutStructure;
}
/**
 *  @fn	void SemanticNodeBlockWait::addSensitivityName(std::string name)
 * 
 *  @brief	Adds a sensitivity name. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	name	The name.
 */
void SemanticNodeBlockWait::addSensitivityName(std::string name) {
	sensitivityListNames.push_back(name);
}
/**
 *  @fn	void SemanticNodeBlockWait::addBlockTerminate(SemanticNodeBlockTerminate *terminator,
 *  	int thenElseTimeout)
 * 
 *  @brief	Adds a block terminate to 'thenElseTimeout'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	terminator		If non-null, the terminator.
 *  @param	thenElseTimeout	The then else timeout.
 */
void SemanticNodeBlockWait::addBlockTerminate(SemanticNodeBlockTerminate *terminator, int thenElseTimeout) {
	terminators.push_back(terminator);
	if (thenElseTimeout == 0) thenBlockOrder.push_back(terminator);
	else if (thenElseTimeout == 1) elseBlockOrder.push_back(terminator);
	else timeoutBlockOrder.push_back(terminator);
}
/**
 *  @fn	void SemanticNodeBlockWait::addBlockGenerate(SemanticNodeBlockGenerate *generator,
 *  	int thenElseTimeout)
 * 
 *  @brief	Adds a block generate to 'thenElseTimeout'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	generator		If non-null, the generator.
 *  @param	thenElseTimeout	The then else timeout.
 */
void SemanticNodeBlockWait::addBlockGenerate(SemanticNodeBlockGenerate *generator, int thenElseTimeout) {
	generators.push_back(generator);
	if (thenElseTimeout == 0) thenBlockOrder.push_back(generator);
	else if (thenElseTimeout == 1) elseBlockOrder.push_back(generator);
	else timeoutBlockOrder.push_back(generator);
}
/**
 *  @fn	void SemanticNodeBlockWait::addBlockAdvance(SemanticNodeBlockAdvance *advancer,
 *  	int thenElseTimeout)
 * 
 *  @brief	Adds a block advance to 'thenElseTimeout'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	advancer		If non-null, the advancer.
 *  @param	thenElseTimeout	The then else timeout.
 */
void SemanticNodeBlockWait::addBlockAdvance(SemanticNodeBlockAdvance *advancer, int thenElseTimeout) {
	advancers.push_back(advancer);
	if (thenElseTimeout == 0) thenBlockOrder.push_back(advancer);
	else if (thenElseTimeout == 1) elseBlockOrder.push_back(advancer);
	else timeoutBlockOrder.push_back(advancer);
}
/**
 *  @fn	void SemanticNodeBlockWait::addBlockEnter(SemanticNodeBlockEnter *entrant,
 *  	int thenElseTimeout)
 * 
 *  @brief	Adds a block enter to 'thenElseTimeout'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	entrant			If non-null, the entrant.
 *  @param	thenElseTimeout	The then else timeout.
 */
void SemanticNodeBlockWait::addBlockEnter(SemanticNodeBlockEnter *entrant, int thenElseTimeout) {
	entrants.push_back(entrant);
	if (thenElseTimeout == 0) thenBlockOrder.push_back(entrant);
	else if (thenElseTimeout == 1) elseBlockOrder.push_back(entrant);
	else timeoutBlockOrder.push_back(entrant);
}
/**
 *  @fn	void SemanticNodeBlockWait::addBlockLeave(SemanticNodeBlockLeave *leaver,
 *  	int thenElseTimeout)
 * 
 *  @brief	Adds a block leave to 'thenElseTimeout'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	leaver			If non-null, the leaver.
 *  @param	thenElseTimeout	The then else timeout.
 */
void SemanticNodeBlockWait::addBlockLeave(SemanticNodeBlockLeave *leaver, int thenElseTimeout) {
	leavers.push_back(leaver);
	if (thenElseTimeout == 0) thenBlockOrder.push_back(leaver);
	else if (thenElseTimeout == 1) elseBlockOrder.push_back(leaver);
	else timeoutBlockOrder.push_back(leaver);
}
/**
 *  @fn	void SemanticNodeBlockWait::addBlockSeize(SemanticNodeBlockSeize *seizer,
 *  	int thenElseTimeout)
 * 
 *  @brief	Adds a block seize to 'thenElseTimeout'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	seizer			If non-null, the seizer.
 *  @param	thenElseTimeout	The then else timeout.
 */
void SemanticNodeBlockWait::addBlockSeize(SemanticNodeBlockSeize *seizer, int thenElseTimeout) {
	seizers.push_back(seizer);
	if (thenElseTimeout == 0) thenBlockOrder.push_back(seizer);
	else if (thenElseTimeout == 1) elseBlockOrder.push_back(seizer);
	else timeoutBlockOrder.push_back(seizer);
}
/**
 *  @fn	void SemanticNodeBlockWait::addBlockRelease(SemanticNodeBlockRelease *releaser,
 *  	int thenElseTimeout)
 * 
 *  @brief	Adds a block release to 'thenElseTimeout'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	releaser		If non-null, the releaser.
 *  @param	thenElseTimeout	The then else timeout.
 */
void SemanticNodeBlockWait::addBlockRelease(SemanticNodeBlockRelease *releaser, int thenElseTimeout) {
	releasers.push_back(releaser);
	if (thenElseTimeout == 0) thenBlockOrder.push_back(releaser);
	else if (thenElseTimeout == 1) elseBlockOrder.push_back(releaser);
	else timeoutBlockOrder.push_back(releaser);
}
/**
 *  @fn	void SemanticNodeBlockWait::addBlockInqueue(SemanticNodeBlockInqueue *inqueuer,
 *  	int thenElseTimeout)
 * 
 *  @brief	Adds a block inqueue to 'thenElseTimeout'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	inqueuer		If non-null, the inqueuer.
 *  @param	thenElseTimeout	The then else timeout.
 */
void SemanticNodeBlockWait::addBlockInqueue(SemanticNodeBlockInqueue *inqueuer, int thenElseTimeout) {
	inqueuers.push_back(inqueuer);
	if (thenElseTimeout == 0) thenBlockOrder.push_back(inqueuer);
	else if (thenElseTimeout == 1) elseBlockOrder.push_back(inqueuer);
	else timeoutBlockOrder.push_back(inqueuer);
}
/**
 *  @fn	void SemanticNodeBlockWait::addBlockOutqueue(SemanticNodeBlockOutqueue *outqueuer,
 *  	int thenElseTimeout)
 * 
 *  @brief	Adds a block outqueue to 'thenElseTimeout'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	outqueuer		If non-null, the outqueuer.
 *  @param	thenElseTimeout	The then else timeout.
 */
void SemanticNodeBlockWait::addBlockOutqueue(SemanticNodeBlockOutqueue *outqueuer, int thenElseTimeout) {
	outqueuers.push_back(outqueuer);
	if (thenElseTimeout == 0) thenBlockOrder.push_back(outqueuer);
	else if (thenElseTimeout == 1) elseBlockOrder.push_back(outqueuer);
	else timeoutBlockOrder.push_back(outqueuer);
}
/**
 *  @fn	void SemanticNodeBlockWait::addBlockArrive(SemanticNodeBlockArrive *arrivee,
 *  	int thenElseTimeout)
 * 
 *  @brief	Adds a block arrive to 'thenElseTimeout'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	arrivee			If non-null, the arrivee.
 *  @param	thenElseTimeout	The then else timeout.
 */
void SemanticNodeBlockWait::addBlockArrive(SemanticNodeBlockArrive *arrivee, int thenElseTimeout) {
	arrivals.push_back(arrivee);
	if (thenElseTimeout == 0) thenBlockOrder.push_back(arrivee);
	else if (thenElseTimeout == 1) elseBlockOrder.push_back(arrivee);
	else timeoutBlockOrder.push_back(arrivee);
}
/**
 *  @fn	void SemanticNodeBlockWait::addBlockDepart(SemanticNodeBlockDepart *departure,
 *  	int thenElseTimeout)
 * 
 *  @brief	Adds a block depart to 'thenElseTimeout'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	departure		If non-null, the departure.
 *  @param	thenElseTimeout	The then else timeout.
 */
void SemanticNodeBlockWait::addBlockDepart(SemanticNodeBlockDepart *departure, int thenElseTimeout) {
	departures.push_back(departure);
	if (thenElseTimeout == 0) thenBlockOrder.push_back(departure);
	else if (thenElseTimeout == 1) elseBlockOrder.push_back(departure);
	else timeoutBlockOrder.push_back(departure);
}
/**
 *  @fn	void SemanticNodeBlockWait::addBlockModelInstance(SemanticNodeBlockModelInstance *modelInst
 *  	ance, int thenElseTimeout)
 * 
 *  @brief	Adds a block model instance to 'thenElseTimeout'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	modelInstance	If non-null, the model instance.
 *  @param	thenElseTimeout	The then else timeout.
 */
void SemanticNodeBlockWait::addBlockModelInstance(SemanticNodeBlockModelInstance *modelInstance, int thenElseTimeout) {
	modelInstances.push_back(modelInstance);
	if (thenElseTimeout == 0) thenBlockOrder.push_back(modelInstance);
	else if (thenElseTimeout == 1) elseBlockOrder.push_back(modelInstance);
	else timeoutBlockOrder.push_back(modelInstance);
}
/**
 *  @fn	void SemanticNodeBlockWait::addBlockGoto(SemanticNodeBlockGoto *gotoer,
 *  	int thenElseTimeout)
 * 
 *  @brief	Adds a block goto to 'thenElseTimeout'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	gotoer			If non-null, the gotoer.
 *  @param	thenElseTimeout	The then else timeout.
 */
void SemanticNodeBlockWait::addBlockGoto(SemanticNodeBlockGoto *gotoer, int thenElseTimeout) {
	gotos.push_back(gotoer);
	if (thenElseTimeout == 0) thenBlockOrder.push_back(gotoer);
	else if (thenElseTimeout == 1) elseBlockOrder.push_back(gotoer);
	else timeoutBlockOrder.push_back(gotoer);
}
/**
 *  @fn	void SemanticNodeBlockWait::addBlockIf(SemanticNodeBlockIf *ifer, int thenElseTimeout)
 * 
 *  @brief	Adds a block if to 'thenElseTimeout'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	ifer			If non-null, the ifer.
 *  @param	thenElseTimeout	The then else timeout.
 */
void SemanticNodeBlockWait::addBlockIf(SemanticNodeBlockIf *ifer, int thenElseTimeout) {
	ifs.push_back(ifer);
	if (thenElseTimeout == 0) thenBlockOrder.push_back(ifer);
	else if (thenElseTimeout == 1) elseBlockOrder.push_back(ifer);
	else timeoutBlockOrder.push_back(ifer);
}
/**
 *  @fn	void SemanticNodeBlockWait::addBlockWait(SemanticNodeBlockWait *waiter,
 *  	int thenElseTimeout)
 * 
 *  @brief	Adds a block wait to 'thenElseTimeout'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	waiter			If non-null, the waiter.
 *  @param	thenElseTimeout	The then else timeout.
 */
void SemanticNodeBlockWait::addBlockWait(SemanticNodeBlockWait *waiter, int thenElseTimeout) {
	waiters.push_back(waiter);
	if (thenElseTimeout == 0) thenBlockOrder.push_back(waiter);
	else if (thenElseTimeout == 1) elseBlockOrder.push_back(waiter);
	else timeoutBlockOrder.push_back(waiter);
}
/**
 *  @fn	void SemanticNodeBlockWait::addBlockJoinGroup(SemanticNodeBlockJoinGroup *groupJoiner,
 *  	int thenElseTimeout)
 * 
 *  @brief	Adds a block join group to 'thenElseTimeout'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	groupJoiner		If non-null, the group joiner.
 *  @param	thenElseTimeout	The then else timeout.
 */
void SemanticNodeBlockWait::addBlockJoinGroup(SemanticNodeBlockJoinGroup *groupJoiner, int thenElseTimeout) {
	groupJoiners.push_back(groupJoiner);
	if (thenElseTimeout == 0) thenBlockOrder.push_back(groupJoiner);
	else if (thenElseTimeout == 1) elseBlockOrder.push_back(groupJoiner);
	else timeoutBlockOrder.push_back(groupJoiner);
}
/**
 *  @fn	void SemanticNodeBlockWait::addBlockLeaveGroup(SemanticNodeBlockLeaveGroup *groupLeaver,
 *  	int thenElseTimeout)
 * 
 *  @brief	Adds a block leave group to 'thenElseTimeout'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	groupLeaver		If non-null, the group leaver.
 *  @param	thenElseTimeout	The then else timeout.
 */
void SemanticNodeBlockWait::addBlockLeaveGroup(SemanticNodeBlockLeaveGroup *groupLeaver, int thenElseTimeout) {
	groupLeavers.push_back(groupLeaver);
	if (thenElseTimeout == 0) thenBlockOrder.push_back(groupLeaver);
	else if (thenElseTimeout == 1) elseBlockOrder.push_back(groupLeaver);
	else timeoutBlockOrder.push_back(groupLeaver);
}
/**
 *  @fn	void SemanticNodeBlockWait::addBlockCreate(SemanticNodeBlockCreate *creator,
 *  	int thenElseTimeout)
 * 
 *  @brief	Adds a block create to 'thenElseTimeout'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	creator			If non-null, the creator.
 *  @param	thenElseTimeout	The then else timeout.
 */
void SemanticNodeBlockWait::addBlockCreate(SemanticNodeBlockCreate *creator, int thenElseTimeout) {
	creators.push_back(creator);
	if (thenElseTimeout == 0) thenBlockOrder.push_back(creator);
	else if (thenElseTimeout == 1) elseBlockOrder.push_back(creator);
	else timeoutBlockOrder.push_back(creator);
}
/**
 *  @fn	void SemanticNodeBlockWait::addBlockSplit(SemanticNodeBlockSplit *splitter,
 *  	int thenElseTimeout)
 * 
 *  @brief	Adds a block split to 'thenElseTimeout'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	splitter		If non-null, the splitter.
 *  @param	thenElseTimeout	The then else timeout.
 */
void SemanticNodeBlockWait::addBlockSplit(SemanticNodeBlockSplit *splitter, int thenElseTimeout) {
	splitters.push_back(splitter);
	if (thenElseTimeout == 0) thenBlockOrder.push_back(splitter);
	else if (thenElseTimeout == 1) elseBlockOrder.push_back(splitter);
	else timeoutBlockOrder.push_back(splitter);
}
/**
 *  @fn	void SemanticNodeBlockWait::addBlockGather(SemanticNodeBlockGather *gatherer,
 *  	int thenElseTimeout)
 * 
 *  @brief	Adds a block gather to 'thenElseTimeout'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	gatherer		If non-null, the gatherer.
 *  @param	thenElseTimeout	The then else timeout.
 */
void SemanticNodeBlockWait::addBlockGather(SemanticNodeBlockGather *gatherer, int thenElseTimeout) {
	gatherers.push_back(gatherer);
	if (thenElseTimeout == 0) thenBlockOrder.push_back(gatherer);
	else if (thenElseTimeout == 1) elseBlockOrder.push_back(gatherer);
	else timeoutBlockOrder.push_back(gatherer);
}
/**
 *  @fn	void SemanticNodeBlockWait::addBlockExecute(SemanticNodeBlockExecute *executor,
 *  	int thenElseTimeout)
 * 
 *  @brief	Adds a block execute to 'thenElseTimeout'. 
 * 
 *  @author	Nikola Novak
 *  @date	6/26/2009
 * 
 *  @param	executor		If non-null, the executor.
 *  @param	thenElseTimeout	The then else timeout.
 */
void SemanticNodeBlockWait::addBlockExecute(SemanticNodeBlockExecute *executor, int thenElseTimeout) {
	executors.push_back(executor);
	if (thenElseTimeout == 0) thenBlockOrder.push_back(executor);
	else if (thenElseTimeout == 1) elseBlockOrder.push_back(executor);
	else timeoutBlockOrder.push_back(executor);
}
/**
 *  @fn	std::string SemanticNodeBlockWait::toDebugString(int tab)
 * 
 *  @brief	Converts a tab to a debug string. 
 * 
 *  @author	Nikola Novak
 *  @date	6/25/2009
 * 
 *  @param	tab	The tab.
 * 
 *  @return	This object as a std::string.
 */
std::string SemanticNodeBlockWait::toDebugString(int tab) {
	std::ostringstream res;
	for (int i = 0; i < tab; i++) res << DEBUG_STRING_RAZMAK;
	res << getLabelsDebugString() << ": wait";
	if (sensitivityList) {
		res << " on ";
		for (std::vector<std::string>::iterator i = sensitivityListNames.begin(); i != sensitivityListNames.end(); ) {
			res << *i;
			if (++i != sensitivityListNames.end()) res << ", ";
		}
	}
	res << " ";
	if (queue) {
		res << "forming" << std::endl;
		res << ((SemanticNode *)formingQueue)->toDebugString(tab + 1);
		for (int i = 0; i < tab; i++) res << DEBUG_STRING_RAZMAK;
	}
	if (whileUntil) res << "until";
	else res << "while";
	res << std::endl << ((SemanticNode *)condition)->toDebugString(tab + 1);
	if (thenStructure || elseStructure || timeout) {
		for (int i = 0; i < tab; i++) res << DEBUG_STRING_RAZMAK;
	}
	if (thenStructure) {
		res << "then {" << std::endl;
		for (std::vector<SemanticNode *>::iterator i = thenBlockOrder.begin(); i != thenBlockOrder.end(); ++i) {
			res << (*i)->toDebugString(tab + 1);
		}
		for (int i = 0; i < tab; i++) res << DEBUG_STRING_RAZMAK;
		res << "} ";
	}
	if (elseStructure) {
		res << "else {" << std::endl;
		for (std::vector<SemanticNode *>::iterator i = elseBlockOrder.begin(); i != elseBlockOrder.end(); ++i) {
			res << (*i)->toDebugString(tab + 1);
		}
		for (int i = 0; i < tab; i++) res << DEBUG_STRING_RAZMAK;
		res << "} ";
	}
	if (timeout) {
		res << "timeout (" << std::endl << ((SemanticNode *)timeoutExpression)->toDebugString(tab + 1);
		for (int i = 0; i < tab; i++) res << DEBUG_STRING_RAZMAK;
		res << ")";
	 if (timeoutStructure) {
	 	res << " {" << std::endl;
	 	for (std::vector<SemanticNode *>::iterator i = timeoutBlockOrder.begin(); i != timeoutBlockOrder.end(); ++i) {
	 		res << (*i)->toDebugString(tab + 1);
	 	}
	 	for (int i = 0; i < tab; i++) res << DEBUG_STRING_RAZMAK;
	 	res << "} ";
	 }
	}
	if (thenStructure || elseStructure || timeout) res << std::endl;
	return res.str();
}
